$(shell ./env.sh > make.env)
include make.env

SRCDIR:=metaimage-$(GIT_REVSHORT)
PACKAGE:=metaimage-$(PKG_VERSION)-$(PKG_RELEASE)
FILES:=$(shell find ../* -type f -iname '*.py' -o -iname '*.sh')

work/$(GIT_REVISION).tar.gz: $(FILES)
	cd work ; ln -s ../.. $(SRCDIR) ; \
	tar -chaf $(GIT_REVISION).tar.gz \
	    --exclude work \
	    --exclude test \
	    --exclude make.env \
	    $(SRCDIR)/* ; rm $(SRCDIR)

work/PKGBUILD: pkgbuild.sh ../src/__init__.py
	./pkgbuild.sh > work/PKGBUILD

work/$(PACKAGE).src.tar.gz: work/PKGBUILD
	cd work; mkaurball

work/$(PACKAGE)-any.pkg.tar.xz: work/PKGBUILD work/$(GIT_REVISION).tar.gz
	cd work; makepkg -s

.PHONY: pkgbuild aurball package install clean
pkgbuild: work/PKGBUILD

aurball: work/$(PACKAGE).src.tar.gz

package: work/$(PACKAGE)-any.pkg.tar.xz

install: work/$(PACKAGE)-any.pkg.tar.xz
	sudo pacman -U work/$(PACKAGE)-any.pkg.tar.xz

clean:
	rm make.env
	rm -r work
